package com.sdgs.paas.sdk.app;

import static com.sdgs.paas.sdk.core.environment.EnviromentBuilder.buildAppEnv;

import org.mybatis.spring.boot.autoconfigure.MybatisAutoConfiguration;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.AutoConfigurationExcludeFilter;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.data.jpa.JpaRepositoriesAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
import org.springframework.boot.context.TypeExcludeFilter;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.ComponentScan.Filter;
import org.springframework.context.annotation.FilterType;

import com.sdgs.paas.sdk.core.log.EnablePaasLog;
import com.sdgs.paas.sdk.core.log.PaasLogger;
import com.sdgs.paas.sdk.core.metrics.EnablePaasMethodMetrics;
import com.sdgs.paas.sdk.core.web.EnablePaasWebMVC;
import com.sdgs.paas.sdk.core.web.client.EnablePaasRestTemplate;
import com.sdgs.paas.sdk.core.web.loadbalance.EnablePaasLoadBalance;

/**
 * 所有微服务的启动类
 * 
 * @author wjj
 * 
 */
@SpringBootApplication
@EnablePaasLog
@EnablePaasMethodMetrics
@EnablePaasWebMVC
@EnablePaasRestTemplate
@EnablePaasLoadBalance
@EnableDiscoveryClient
// @EnableFeignClients("${shtelpaas.app.basepkg}")
@EnableCircuitBreaker
@EnableAutoConfiguration(exclude = { JpaRepositoriesAutoConfiguration.class,HibernateJpaAutoConfiguration.class, DataSourceAutoConfiguration.class,
		MybatisAutoConfiguration.class })
@ComponentScan(value = { "${shtelpaas.app.basepkg}" }, excludeFilters = {
		@Filter(type = FilterType.REGEX, pattern = "com\\.sdgs\\.paas\\.sdk\\.core.*"),
		@Filter(type = FilterType.CUSTOM, classes = TypeExcludeFilter.class),
		@Filter(type = FilterType.CUSTOM, classes = AutoConfigurationExcludeFilter.class) })
public class PaasMainApp {

	public static void main(String[] args) {

		String[] newargs = buildAppEnv(args);
		ConfigurableApplicationContext ctx = SpringApplication.run(PaasMainApp.class, newargs);
		PaasLogger.info("PaasMainApp 启动完毕！应用名称:{}", ctx.getId());
	}

}
